<?php
//课时
defined('IN_TS') or die('Access Denied.');

$lessonid = intval($_GET['lessonid']);		
$strLesson = $new['study']->find('study_lesson',array(
	'lessonid'=>$lessonid,
));

$strLesson['user'] = aac('user')->getOneUser($strLesson['userid']); 


/*统一控制课程头部信息开始*****************/
$strStudy = $new['study']->getOneStudy($strLesson['studyid']);
$strStudy['user'] = aac('user')->getOneUser($strStudy['userid']);
//获取课程的分类
$strStudy['onecate'] = $new['study']->find('study_cates',array(
	'cateid'=>$strStudy['cateid'],
));

/*
$strStudy['twocate'] = $new['study']->find('study_cates',array(
	'cateid2'=>$strStudy['cateid2'],
));
*/



//判断用户学习状态,未学习为空，学习了获取学习信息
$strStudy['learn'] = '';
if(intval($TS_USER['userid'])){
	//用户学习状态
	$strStudy['learn'] = $new['study']->find('study_learn',array(
		'userid'=>intval($TS_USER['userid']),
		'studyid'=>$strStudy['studyid'],
	));
	//用户已经学课时
	$arrLessonUsers = $new['study']->findAll('study_lesson_user',array(
		'userid'=>intval($TS_USER['userid']),
		'studyid'=>$studyid,
	));
}



/*统一控制课程头部信息结束******************/




/////////////////分类导航开始/////////////////
//一级分类信息
$oneCate = $new['study']->find('study_cates',array(
	'cateid'=>$strStudy['cateid'],
));
//二级分类列表
$arrTwoCate = $new['study']->findAll('study_cates',array(
	'recateid'=>$oneCate['cateid'],
));
/////////////////分类导航结束/////////////////



$isLessonUser = 0;//是否学习完此课时的人

if($TS_USER['userid']){

	$userid = $TS_USER['userid'];
	
	
	//是否学习完此课程
	if($strLesson['userid'] != $userid){
		$isLessonUser = $new['study']->findCount('study_lesson_user',array(
			'userid'=>$userid,
			'lessonid'=>$lessonid,
		));
	}

}

		


//课程下课时列表
$arrLesson = $new['study']->findAll('study_lesson',array(
	'studyid'=>$strStudy['studyid'],
),'orderid asc');



//最近学完课时的人

$page = isset ( $_GET ['page'] ) ? intval ( $_GET ['page'] ) : 1;
$url = tsUrl ( 'study', 'lessonuser', array ('lessonid'=>$strLesson['lessonid'],'page' =>'') );
$lstart = $page * 48 - 48;

$arrLessonUsers = $new['study']->findAll('study_lesson_user',array(
	'lessonid'=>$strLesson['lessonid'],
),'addtime desc',null,$lstart.',48');


$userNum = $new ['study']->findCount ( 'study_lesson_user', array (
	'lessonid'=>$strLesson['lessonid'],
) );
$pageUrl = pagination ( $userNum, 48, $page, $url );


foreach($arrLessonUsers as $key=>$item){

	$arrLessonUser[] = aac('user')->getOneUser($item['userid']);

}

$title = '第'.$strLesson['orderid'].'课 '.$strLesson['title'].'学完的用户_'.$strStudy['studyname'];
include template('lessonuser');